from protocol.models import Committee, Institution, Protocol, Revision, RevisionName, RevisionFile
from django.contrib import admin
from reversion.admin import VersionAdmin

class CommitteeAdmin(VersionAdmin):
    """Add Documentation"""

class InstitutionAdmin(VersionAdmin):
    """Add Documentation"""

class ProtocolAdmin(VersionAdmin):
    fieldsets = (
        (None, {
            'fields': ('name', ('institution', 'committee', 'reference_code'), 'lab', 'protocol_status','researchers',)
        }),
    )
    readonly_fields = ('name',)
    list_display = ('name', 'protocol_status',)
    list_editable = ('protocol_status',)

class RevisionNameAdmin(VersionAdmin):
    """Add Documentation"""
    

class RevisionAdmin(VersionAdmin):
    """Add Documentation"""
    list_display = ('protocol', 'name', 'year', 'version', 'details',)
    readonly_fields = ('version',)
    
    def save_model(self, request, obj, form, change):
        if obj.researcher is None:
            obj.researcher = request.user.get_profile()
        obj.save()
    


class RevisionFileAdmin(VersionAdmin):
    """Add Documentation"""


admin.site.register(Committee, CommitteeAdmin)
admin.site.register(Institution, InstitutionAdmin)
admin.site.register(Protocol, ProtocolAdmin)
admin.site.register(RevisionName, RevisionNameAdmin)
admin.site.register(Revision, RevisionAdmin)
admin.site.register(RevisionFile, RevisionFileAdmin)
